package com.liu.lab04.listener;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;

public class MyListener implements ServletContextListener  {
    private static final String PAGE_VISIT_COUNT = "pageVisitCount";
    private static int pageVisitCount = 0;
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // 初始化页面访问计数器
        ServletContext context = sce.getServletContext();
        pageVisitCount++;
        context.setAttribute(PAGE_VISIT_COUNT, pageVisitCount);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // 在应用程序关闭时执行清理操作（可选）
    }
}
